#include"guiApp.h"
#include"mLcd9488.H"
#include "gui_guider.h"
#include "custom.h"
#include "widgets_init.h"

lv_ui guider_ui;
static lv_disp_drv_t* lv_disp_drv_p = NULL;
#  define MONITOR_HOR_RES     LV_HOR_RES_MAX
#  define MONITOR_VER_RES     LV_VER_RES_MAX
extern 
void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
   lv_disp_drv_p = disp_drv;  
        /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/

        int32_t x;
        int32_t y;
       LCD_SetWindows(area->x1,area->y1,area->x2,area->y2);  
        for(y = area->y1; y <= area->y2; y++) {
            for(x = area->x1; x <= area->x2; x++) {
                /*Put a pixel to the display. For example:*/
                /*put_px(x, y, *color_p)*/
                Lcd_WriteData_16Bit(color_p->full);
                color_p++;
            }
        }
    

    /*IMPORTANT!!!
     *Inform the graphics library that you are ready with the flushing*/
    lv_disp_flush_ready(disp_drv);

}

 static lv_disp_drv_t disp_drv;
void  hal_init(void)
{
    /*Create a display buffer*/
    static lv_disp_draw_buf_t disp_buf1;
    static lv_color_t buf1_1[480 * 10] @SDRAMM_BASE;
    lv_disp_draw_buf_init(&disp_buf1, buf1_1, NULL, 480 * 10);

    /*Create a display*/
   
    lv_disp_drv_init(&disp_drv);            /*Basic initialization*/
    disp_drv.draw_buf = &disp_buf1;
    disp_drv.flush_cb = monitor_flush;
    disp_drv.hor_res = MONITOR_HOR_RES;
    disp_drv.ver_res = MONITOR_VER_RES;
    lv_disp_drv_register(&disp_drv);
	eDispFlush_cbInit(&monitor_flush);
}

void  mGuiApp(void *arg)
{
//LCD9488_Init();
TP_Init();
//TP_Adjust();
    /*Initialize the HAL (display, input devices, tick) for LittlevGL*/
  lv_init();
hal_init();
    /*Create a GUI-Guider app */
    setup_ui(&guider_ui);
	custom_init(&guider_ui);
	while(1)
	{
        //   lv_task_handler();
		vTaskDelay(1);
		TP_ReadTest();
	//	 lv_tick_inc(1); /*Tell LittelvGL that 5 milliseconds were elapsed*/
	}
}

